/*
 *  Sudoku-Solver-java, a Sudoku puzzle solver, written in Java
 *  Copyright (C) 2010  C.Kruse aka Briezh
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *  Homepage: http://code.google.com/p/sudoku-solver-java/
 *  Contact : briezh@gmail.com
 */

/**
 * 
 */
package sudokusolver;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Briezh
 */
public class Main {
    /**
     * Copyright information
     */
    private static
        String CPY="Sudoku-Solver-java, a Sudoku solver, written in Java\n"
                  +"Copyright (C) 2010  C.Kruse aka Briezh";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        /*
         * Constant copyright information;
         * should be the first issue by running the program.
         */
        System.out.println(CPY+"\n\n");//write copyright

        for( int i=0; i<args.length; i++) {
            System.out.print(args[i]);
            try {
                if (checkArgs(args, i)) {
                    i++;
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        printV("Matrix X:" + MatrixX);
        printV("Matrix Y:" + MatrixY);
    }

    private static int MatrixX;
    private static int MatrixY;
    private static boolean verbose;

    private static void printV(String s){
        if(verbose==true){
                System.out.println(s);
        }
    }

    private static boolean checkArgs(String[] args, int pos) 
                throws FileNotFoundException, IOException {
        if(args[pos].equals("-h") ||
           args[pos].equals("-?") ||
           args[pos].equals("--help")){
            // TODO Write helpe text
            FileReader fr = new FileReader("c:\\help.txt");
            BufferedReader br = new BufferedReader(fr);
            String Line = CPY;
            while(Line != null) {
                System.out.println(Line);
                Line = br.readLine();
            } br.close();
            
            return false;
        }
        if(args[pos].equals("-c") ||
           args[pos].equals("-w") ){
            // TODO Write Copyright
            System.out.println("-> Copyright");
            return false;
        }
        if(args[pos].equals("-V") ||
           args[pos].equals("--version") ){
            // TODO Add parameter for version
            // TODO write version output
            System.out.println("-> Version");
            return false;
        }
        if(args[pos].equals("-mx")){
            System.out.print("-> Matrix X, before("+MatrixX+")");
            MatrixX = Integer.valueOf(args[pos+1]);
            System.out.println(", now("+MatrixX+")");
            return true;

        }
        if(args[pos].equals("-my")){
            System.out.print("-> Matrix Y, before("+MatrixY+")");
            MatrixY = Integer.valueOf(args[pos+1]);
            System.out.println(", now("+MatrixY+")");
            return true;
        }

        return false;
    }
}
